home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / docs / tcexample.php next >
PHP Script  |  2004-03-24  |  4KB  |  102 lines

  1. <?
  2.     // This example assumes that tclink.so has already been loaded.
  3.     // Normally this is done by adding "extension=tclink.so" to your
  4.     // php.ini, but you may also make a manual call to dl("tclink")
  5.     // as well.  See tctest.php for example code.
  6.  
  7.     if (!$custid) $custid = "TestMerchant";
  8.     if (!$password) $password = "password";
  9. ?>
  10. <html>
  11. <head><title>TCLink PHP Example</title></head>
  12. <body bgcolor=white text=black>
  13.  
  14.     <form method="post" action="<?= $PHP_SELF ?>">
  15.  
  16.     <table cellspacing=1 cellpadding=3>
  17.     <tr bgcolor=blue><th colspan=2 align=center>
  18.         <font color=white>TrustCommerce PHP Example - TCLink ver. <?= tclink_getversion() ?>)</font>
  19.     </th></tr>
  20.  
  21.     <tr><th align=right> CustID: </td><td> <input type="text" name="custid" value="<?= $custid ?>"> </td></tr>
  22.     <tr><th align=right> Password: </td><td> <input type="text" name="password" value="<?= $password ?>"> </td></tr>
  23.     <tr><th align=right> Action: </td><td> <select name="action">
  24.         <option value="sale">Sale</option>
  25.         <option value="preauth">Pre-Authorization</option>
  26.         <option value="postauth">Post-Authorization</option>
  27.         <option value="credit">Credit</option>
  28.     </select> </td></tr>
  29.     <tr><th align=right> Amount (in cents):</td><td> <input type="text" name="amount"> </td></tr>
  30.     <tr bgcolor=lightgray><td colspan=2 align=center> Sales and Pre-Authorizations Only: </td></tr>
  31.     <tr><th align=right> Card Number: </td><td> <input type="text" name="cc" size="16" maxlength="16"> </td></tr>
  32.     <tr><th align=right> Expiration: </td>
  33.         <td><select name="mm"><? for ($i = 1; $i <= 12; $i++) { ?><option value="<?=sprintf("%02d", $i);?>"><?=sprintf("%02d", $i);?></option><? } ?></select>
  34.             <select name="yy"><? for($i = (strftime("%Y")); $i <= (strftime("%Y") + 10); $i++) { ?><option value="<?=substr(sprintf("%04d", $i),2,2);?>"><?=$i;?></option><? } ?></select><br>
  35.         </td></tr>
  36.     <tr><th align=right> Cardholder Name: </td><td> <input type="text" name="name"> </td></tr>
  37.     <tr bgcolor=lightgray><td colspan=2 align=center> Credits and Post-Authorizations Only: </td></tr>
  38.     <tr><th align=right> Transaction ID: </td><td> <input type="text" name="transid" size="14" maxlength="14"> </td></tr>
  39.     <tr><td colspan=2 align=center> <input type="submit" name="Action" value="Process"> </td></tr>
  40.  
  41.     <?
  42.         if ($Action == 'Process')
  43.         {
  44.             $tclink['custid'] = $custid;
  45.             $tclink['password'] = $password;
  46.             $tclink['action'] = $action;
  47.             if (is_numeric($amount))
  48.                 $tclink['amount'] = $amount;
  49.  
  50.             if ($action == 'sale' || $action == 'preauth')
  51.             {
  52.                 $tclink['name'] = $name;
  53.                 $tclink['cc'] = $cc;
  54.                 $tclink['exp'] = $mm . $yy;
  55.             }
  56.             else if ($action == 'credit' || $action == 'postauth')
  57.             {
  58.                 $tclink['transid'] = $transid;
  59.             }
  60.  
  61.             $result = tclink_send($tclink);
  62.  
  63.             print "<tr><td colspan=2><hr></td></tr>";
  64.             print "<tr bgcolor=blue><th colspan=2 align=center><font color=white>Transaction Results:</font></td></tr>";
  65.  
  66.             if ($result['transid'])
  67.                 printf("<tr><th>Transaction ID:</th><td>%s</td></tr>\n", $result['transid']);
  68.  
  69.             printf("<tr><th>Status:</td><td>%s</td></tr>\n", $result['status']);
  70.             switch($result['status'])
  71.             {
  72.                 case 'accepted':
  73.                 case 'approved':
  74.                     break;
  75.  
  76.                 case 'decline':
  77.                 case 'rejected':
  78.                     printf("<tr><th>Decline Type:</th><td>%s</td></tr>\n", $result['declinetype']);
  79.                     break;
  80.  
  81.                 case 'error':
  82.                     printf("<tr><th>Error Type</th><td>%s</td></tr>\n", $result['errortype']);
  83.                     break;
  84.  
  85.                 case 'baddata':
  86.                     printf("<tr><th>Offenders:</th><td>%s</td></tr>\n", $result['$offenders']);
  87.                     break;
  88.             }
  89.  
  90.             print "<tr bgcolor=lightgray><td colspan=2 align=center>All Results:</td></tr>";
  91.  
  92.             while(list($key, $value) = each($result))
  93.                 printf("<tr><th>%s</th><td>%s</td></tr>\n", $key, $value);
  94.         }
  95.     ?>
  96.  
  97. </table>
  98. </form>
  99.  
  100. </body>
  101. </html>
  102.